using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class EOTDREWRITE_FountainCutscene : MonoBehaviour
{
	[Header("Cutscene References")]
	[SerializeField]
	private PlayerManager Kris;

	[SerializeField]
	private GameObject soulShine;

	[SerializeField]
	private Susie_Follower Susie;

	[SerializeField]
	private Susie_Follower Ralsei;

	[SerializeField]
	private EOTDREWRITE_FountainColor fountainColorManager;

	[SerializeField]
	private Transform startingSusiePosition;

	[SerializeField]
	private int CutsceneIndex;

	[SerializeField]
	private Animator[] fountainAnimators;

	[SerializeField]
	private GameObject FountainSealUI;

	[Header("Cutscene Chats")]
	[SerializeField]
	private ChatboxSusieFountain Chatter;

	[SerializeField]
	private INT_Chat ChatterDefault;

	[SerializeField]
	private CHATBOXTEXT susieText;

	[Header("Cutscene Sounds")]
	[SerializeField]
	private AudioSource cutsceneSource;

	[SerializeField]
	private AudioClip SFX_soulShine;

	[SerializeField]
	private AudioClip SFX_dontforget;

	[SerializeField]
	private AudioClip mus_rumble;

	[SerializeField]
	private AudioClip mus_finalfountain;

	private void Start()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		Kris = PlayerManager.Instance;
		Kris.PlayerSpriteRenderer.color = Color.black;
		mus_rumble.LoadAudioData();
		mus_finalfountain.LoadAudioData();
		Ralsei.RotateSusieToDirection(Vector2.up);
		((MonoBehaviour)this).StartCoroutine(Cutscene());
	}

	public void IncrementCutscene()
	{
		CutsceneIndex++;
	}

	private IEnumerator Cutscene()
	{
		yield return null;
		DarkworldMenu.Instance.CanOpenMenu = false;
		Susie = PartyMemberSystem.Instance.HasMemberInParty(PartyMemberSystem.Instance.Default_SusieDarkworld).PartyMemberFollowSettings;
		((Component)((Component)Susie).transform.Find("Shadow")).GetComponent<SpriteRenderer>().color = Color.black;
		((Component)((Component)Susie).transform.Find("FountainLight")).gameObject.SetActive(true);
		fountainColorManager.spriteRenderers.Add(((Component)((Component)Susie).transform.Find("FountainLight")).GetComponent<SpriteRenderer>());
		fountainColorManager.originalDarknesses.Add(1f);
		((Component)Susie.SusieAnimator).GetComponent<SpriteRenderer>().color = Color.black;
		Susie.FollowingEnabled = false;
		((Component)Susie).transform.position = startingSusiePosition.position;
		DEBUG_EnableMarkiplier.ChangeMarkiplierState(DEBUG_EnableMarkiplier.MarkiplierEmotions.Horror);
		yield return (object)new WaitForSeconds(1f);
		while (((Component)Kris).transform.position.y < -2f && ((Component)Susie).transform.position.y < -3f)
		{
			yield return null;
			if (((Component)Kris).transform.position != new Vector3(((Component)Kris).transform.position.x, -2f, 0f))
			{
				((Component)Kris).transform.position = Vector2.op_Implicit(Vector2.MoveTowards(Vector2.op_Implicit(((Component)Kris).transform.position), Vector2.op_Implicit(new Vector3(((Component)Kris).transform.position.x, -2f, 0f)), 1.5f * Time.deltaTime));
				Kris._PMove.AnimationOverriden = true;
				Kris._PMove._anim.SetBool("MOVING", true);
				Kris._PMove._anim.SetFloat("MOVEMENTX", 0f);
				Kris._PMove._anim.SetFloat("MOVEMENTY", 1f);
				Kris._PMove._anim.speed = 0.65f;
			}
			else
			{
				Kris._PMove._anim.SetBool("MOVING", false);
				Kris._PMove._anim.SetFloat("MOVEMENTX", 0f);
				Kris._PMove._anim.SetFloat("MOVEMENTY", 1f);
			}
			if (((Component)Susie).transform.position != new Vector3(((Component)Susie).transform.position.x, -3f, 0f))
			{
				((Component)Susie).transform.position = Vector2.op_Implicit(Vector2.MoveTowards(Vector2.op_Implicit(((Component)Susie).transform.position), Vector2.op_Implicit(new Vector3(((Component)Susie).transform.position.x, -3f, 0f)), 1.5f * Time.deltaTime));
				Susie.AnimationOverriden = true;
				Susie.SusieAnimator.Play("Walk");
				Susie.SusieAnimator.SetFloat("VelocityX", 0f);
				Susie.SusieAnimator.SetFloat("VelocityY", 1f);
				Susie.SusieAnimator.SetFloat("VelocityMagnitude", 1f);
				Susie.SusieAnimator.speed = 0.65f;
			}
			else
			{
				Susie.SusieAnimator.Play("Idle");
				Susie.SusieAnimator.SetFloat("VelocityX", 0f);
				Susie.SusieAnimator.SetFloat("VelocityY", 1f);
				Susie.SusieAnimator.SetFloat("VelocityMagnitude", 1f);
			}
		}
		Kris._PMove._anim.SetBool("MOVING", false);
		Kris._PMove._anim.SetFloat("MOVEMENTX", 0f);
		Kris._PMove._anim.SetFloat("MOVEMENTY", 1f);
		Kris._PMove._anim.speed = 1f;
		Susie.SusieAnimator.Play("Idle");
		Susie.SusieAnimator.SetFloat("VelocityX", 0f);
		Susie.SusieAnimator.SetFloat("VelocityY", 1f);
		Susie.SusieAnimator.SetFloat("VelocityMagnitude", 0f);
		Susie.SusieAnimator.speed = 1f;
		yield return (object)new WaitForSeconds(1.5f);
		Chatter.RunText(susieText, 0, null, ResetCurrentTextIndex: false);
		while (CutsceneIndex < 1)
		{
			yield return null;
		}
		yield return (object)new WaitForSeconds(1f);
		while (((Component)Kris).transform.position.y < -0.75f)
		{
			yield return null;
			if (((Component)Kris).transform.position != new Vector3(((Component)Kris).transform.position.x, -0.75f, 0f))
			{
				((Component)Kris).transform.position = Vector2.op_Implicit(Vector2.MoveTowards(Vector2.op_Implicit(((Component)Kris).transform.position), Vector2.op_Implicit(new Vector3(((Component)Kris).transform.position.x, -0.75f, 0f)), 1.5f * Time.deltaTime));
				Kris._PMove.AnimationOverriden = true;
				Kris._PMove._anim.SetBool("MOVING", true);
				Kris._PMove._anim.SetFloat("MOVEMENTX", 0f);
				Kris._PMove._anim.SetFloat("MOVEMENTY", 1f);
				Kris._PMove._anim.speed = 0.65f;
			}
		}
		Kris._PMove._anim.SetBool("MOVING", false);
		Kris._PMove._anim.SetFloat("MOVEMENTX", 0f);
		Kris._PMove._anim.SetFloat("MOVEMENTY", 1f);
		Kris._PMove._anim.speed = 1f;
		yield return (object)new WaitForSeconds(1f);
		Chatter.RunText(susieText, 1, null, ResetCurrentTextIndex: false);
		DEBUG_EnableMarkiplier.ChangeMarkiplierState(DEBUG_EnableMarkiplier.MarkiplierEmotions.Crying);
		while (CutsceneIndex < 2)
		{
			yield return null;
		}
		soulShine.transform.position = ((Component)Kris).transform.position;
		soulShine.SetActive(true);
		cutsceneSource.PlayOneShot(SFX_soulShine);
		MusicManager.PlaySong(mus_rumble, FadePreviousSong: false, 0f);
		yield return (object)new WaitForSeconds(2.5f);
		DEBUG_EnableMarkiplier.ChangeMarkiplierState(DEBUG_EnableMarkiplier.MarkiplierEmotions.Annoyed);
		UI_FADE.Instance.StartFadeIn(-1, 0.5f);
		while (((Component)CameraManager.instance).transform.position.y < 3.35f)
		{
			yield return null;
			if (((Component)CameraManager.instance).transform.position != new Vector3(((Component)CameraManager.instance).transform.position.x, 3.35f, -10f))
			{
				((Component)CameraManager.instance).transform.position = Vector3.MoveTowards(((Component)CameraManager.instance).transform.position, new Vector3(((Component)CameraManager.instance).transform.position.x, 3.35f, -10f), 1.5f * Time.deltaTime);
			}
		}
		((Component)CameraManager.instance).transform.position = new Vector3(1.5f, 3.5f, -10f);
		UI_FADE.Instance.StartFadeOut(0.5f);
		DEBUG_EnableMarkiplier.ChangeMarkiplierState(DEBUG_EnableMarkiplier.MarkiplierEmotions.Shock);
		MusicManager.PlaySong(mus_finalfountain, FadePreviousSong: true, 0.15f);
		yield return (object)new WaitForSeconds(2f);
		ChatterDefault.RUN();
		Kris.PlayerSpriteRenderer.color = Color.white;
		Kris._PMove.AnimationOverriden = false;
		Kris._PMove.InDarkworld = false;
		LightworldMenu.Instance.CanOpenMenu = false;
		while (CutsceneIndex < 3)
		{
			yield return null;
		}
		DEBUG_EnableMarkiplier.ChangeMarkiplierState(DEBUG_EnableMarkiplier.MarkiplierEmotions.Crying);
		((MonoBehaviour)this).StartCoroutine(songFountainSync());
		while (((Component)CameraManager.instance).transform.position.y < 42f)
		{
			yield return null;
			if (((Component)CameraManager.instance).transform.position != new Vector3(((Component)CameraManager.instance).transform.position.x, 42f, -10f))
			{
				((Component)CameraManager.instance).transform.position = Vector3.MoveTowards(((Component)CameraManager.instance).transform.position, new Vector3(((Component)CameraManager.instance).transform.position.x, 42f, -10f), 4f * Time.deltaTime);
			}
		}
	}

	private IEnumerator songFountainSync()
	{
		yield return (object)new WaitForSeconds(1.5f);
		MusicManager.StopSong(Fade: true, 0.5f);
		cutsceneSource.PlayOneShot(SFX_dontforget);
		Animator[] array = fountainAnimators;
		for (int i = 0; i < array.Length; i++)
		{
			array[i].SetTrigger("PlayFountainSeal");
		}
		yield return (object)new WaitForSeconds(3f);
		FountainSealUI.SetActive(true);
		yield return (object)new WaitForSeconds(1.5f);
		UI_FADE.Instance.StartFadeIn(-1, 0.25f);
		yield return (object)new WaitForSeconds(3.5f);
		SceneManager.LoadScene(23);
	}
}
